package com.pet.web.controller.system;

import com.pet.common.annotation.Log;
import com.pet.common.core.controller.BaseController;
import com.pet.common.core.domain.AjaxResult;
import com.pet.common.core.page.TableDataInfo;
import com.pet.common.enums.BusinessType;
import com.pet.common.utils.poi.ExcelUtil;
import com.pet.system.domain.PetOrders;
import com.pet.system.service.IPetOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单Controller
 *
 * @author pet
 * @date 2022-10-21
 */
@RestController
@RequestMapping("/system/orders")
public class PetOrdersController extends BaseController {
    @Autowired
    private IPetOrdersService petOrdersService;

    /**
     * 查询订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:orders:list')")
    @GetMapping("/list")
    public TableDataInfo list(PetOrders petOrders) {
        startPage();
        List<PetOrders> list = petOrdersService.selectPetOrdersList(petOrders);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:orders:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, PetOrders petOrders) {
        List<PetOrders> list = petOrdersService.selectPetOrdersList(petOrders);
        ExcelUtil<PetOrders> util = new ExcelUtil<PetOrders>(PetOrders.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:orders:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(petOrdersService.selectPetOrdersById(id));
    }

    /**
     * 新增订单
     */
    @PreAuthorize("@ss.hasPermi('system:orders:add')")
    @PostMapping
    public AjaxResult add(@RequestBody PetOrders petOrders) {
        return toAjax(petOrdersService.insertPetOrders(petOrders));
    }

    /**
     * 修改订单
     */
    @PreAuthorize("@ss.hasPermi('system:orders:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody PetOrders petOrders) {
        return toAjax(petOrdersService.updatePetOrders(petOrders));
    }

    /**
     * 删除订单
     */
    @PreAuthorize("@ss.hasPermi('system:orders:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(petOrdersService.deletePetOrdersByIds(ids));
    }
}
